import { DataTypes, Model } from 'sequelize'
import { sequelize } from '../../connect'
import { findAllValues, findOneValue, findOneRandomValue } from '../../public'

type ModelProps = {
  id: number
  name: string
  level: number
  race: string
  affixes: string[]
  equips: string[]
  battle_id: string
  battle_type: string
  battle_camp: string
  battle_index: number
  position: string
  uid: number
  hp_max: number
  mp_max: number
  hp: number
  mp: number
  atk: number
  matk: number
  def: number
  mdef: number
  hit: number
  dodge: number
  crit: number
  crit_dmg: number
  crit_avoid: number
  crit_resist: number
  speed: number
  tenacity: number
  hp_recover: number
  mp_recover: number
  stab_mastery: number
  slash_mastery: number
  strike_mastery: number
  stab_resist: number
  slash_resist: number
  strike_resist: number
  metal_mastery: number
  wood_mastery: number
  water_mastery: number
  fire_mastery: number
  earth_mastery: number
  ice_mastery: number
  thunder_mastery: number
  wind_mastery: number
  light_mastery: number
  dark_mastery: number
  metal_resist: number
  wood_resist: number
  water_resist: number
  fire_resist: number
  earth_resist: number
  ice_resist: number
  thunder_resist: number
  wind_resist: number
  light_resist: number
  dark_resist: number
  base_skill: string[] // 基础技能数组
}

class battle extends Model<ModelProps> {
  public static findAllValues = findAllValues
  public static findOneValue = findOneValue
  public static findOneRandomValue = findOneRandomValue
}

battle.init(
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
      comment: '自增主键'
    },
    name: {
      type: DataTypes.STRING(20),
      allowNull: false,
      defaultValue: '',
      comment: '名字'
    },
    level: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 1,
      comment: '等级'
    },
    race: {
      type: DataTypes.STRING(20),
      allowNull: false,
      defaultValue: '',
      comment: '种族'
    },
    affixes: {
      type: DataTypes.JSON,
      allowNull: true,
      defaultValue: [],
      comment: '词缀'
    },
    equips: {
      type: DataTypes.JSON,
      allowNull: true,
      defaultValue: [],
      comment: '装备'
    },

    battle_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '战斗id'
    },
    battle_type: {
      type: DataTypes.STRING(20),
      allowNull: false,
      defaultValue: '',
      comment: '战斗类型'
    },
    battle_camp: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '阵营'
    },
    battle_index: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '索引'
    },
    position: {
      type: DataTypes.INTEGER,
      allowNull: false,
      comment: '站位'
    },
    uid: {
      type: DataTypes.BIGINT,
      allowNull: false,
      comment: '用户uid'
    },
    hp_max: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '生命上限'
    },
    mp_max: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔力上限'
    },
    hp: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '当前生命'
    },
    mp: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '当前魔力'
    },
    atk: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '物理攻击力'
    },
    matk: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔法攻击力'
    },
    def: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '物理防御力'
    },
    mdef: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔法防御力'
    },
    hit: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '命中'
    },
    dodge: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '闪避'
    },
    crit: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴击'
    },
    crit_dmg: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴伤'
    },
    crit_avoid: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴免'
    },
    crit_resist: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '暴抗'
    },
    speed: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '速度'
    },
    tenacity: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '韧性'
    },
    hp_recover: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '生命恢复'
    },
    mp_recover: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0,
      comment: '魔力恢复'
    },
    stab_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '刺击精通'
    },
    slash_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '斩击精通'
    },
    strike_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '打击精通'
    },
    stab_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '刺击抗性'
    },
    slash_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '斩击抗性'
    },
    strike_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '打击抗性'
    },
    metal_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '金元素精通'
    },
    wood_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '木元素精通'
    },
    water_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '水元素精通'
    },
    fire_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '火元素精通'
    },
    earth_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '土元素精通'
    },
    ice_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '冰元素精通'
    },
    thunder_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '雷元素精通'
    },
    wind_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '风元素精通'
    },
    light_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '光元素精通'
    },
    dark_mastery: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '暗元素精通'
    },
    metal_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '金元素抗性'
    },
    wood_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '木元素抗性'
    },
    water_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '水元素抗性'
    },
    fire_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '火元素抗性'
    },
    earth_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '土元素抗性'
    },
    ice_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '冰元素抗性'
    },
    thunder_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '雷元素抗性'
    },
    wind_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '风元素抗性'
    },
    light_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '光元素抗性'
    },
    dark_resist: {
      type: DataTypes.FLOAT,
      allowNull: false,
      defaultValue: 0,
      comment: '暗元素抗性'
    },
    base_skill: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: '种族基础技能'
    }
  },
  {
    sequelize,
    tableName: 'battle',
    freezeTableName: true,
    createdAt: false,
    updatedAt: false,
    indexes: [
      {
        unique: true,
        fields: ['id']
      }
    ]
  }
)

export { battle }
